import Koa from 'koa';
import KoaRoute from 'koa-router';
import api from './config/'
import routers from './routers/'
import mongoose from 'mongoose'
import request from './utility/fetch';
import { connect, initSchemas }  from './db/init.js';

//链接mongodb数据库
;(async () => {
    await connect()
    initSchemas()
    // 引入movie任务 开启子进程爬虫爬数据 并且存入到数据库中
    // require('./tasks/movies')
    require('./tasks/api')
})()
const app = new Koa();
const port = api.port;
//定义全局使用的方法
global.fetch = request;
const router = new KoaRoute();
app.use(router.routes());
app.use(router.allowedMethods());
routers(router);


app.listen(port);